//
//  LeftController.m
//  漫威
//
//  Created by 梅津山 on 2017/5/9.
//  Copyright © 2017年 梅津山. All rights reserved.
//

#import "LeftController.h"
#import "LeftModel.h"
#import "LeftCell.h"
//#import "MymyController.h"
#import "ViewController.h"
//#import "CollectionController.h"
//#import "AboutUsController.h"
//#import "UserFeedbackController.h"
#import <AVOSCloud/AVOSCloud.h>
#import  <UIImageView+AFNetworking.h>
#import "LYMinuteController.h"

@interface LeftController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIImageView *myImageV;

@property (weak, nonatomic) IBOutlet UILabel *myNameL;

@property (weak, nonatomic) IBOutlet UITableView *tableVc;

@property(nonatomic,strong)NSArray *dataArry;//数据源
@property (weak, nonatomic) IBOutlet UILabel *signatureL;


@end

@implementation LeftController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tableVc.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableVc.delegate = self;
    _tableVc.dataSource = self;
    _tableVc.rowHeight = 80;
    [self UserInfo];
}
//注销
- (IBAction)logout:(UIButton *)sender {
    [AVUser logOut];  //清除缓存用户对象
     AVUser *currentUser = [AVUser currentUser]; // 现在的currentUser是nil了
    NSLog(@"%@",currentUser);
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ViewController *Vc = [sb instantiateViewControllerWithIdentifier:@"ViewController"];
    [self presentViewController:Vc animated:YES completion:nil];
    
}
//获得用户信息
-(void)UserInfo{
    AVUser *currentUser = [AVUser currentUser];
    _myNameL.text = [currentUser objectForKey:@"name"];
    [_myImageV setImageWithURL:[NSURL URLWithString:[currentUser objectForKey:@"image"]]];
    NSLog(@"%@",[currentUser objectForKey:@"image"]);
   // AVQuery *query = [AVQuery queryWithClassName:@"_User"];
   // [query whereKey:@"" equalTo:@"username"];
//    [query includeKey:@"owner"];
//      [query includeKey:@"imageT"];
//  //  [query whereKey:@"owner" equalTo:[AVUser currentUser]];
//      [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
//       // NSLog(@"%@",objects);
//        if (!error) {
//            for (AVObject *obj in objects) {
//                [_myImageV setImageWithURL:[NSURL URLWithString:[obj objectForKey:@"imageT"]]];
//                _myNameL.text = [obj objectForKey:@"name"];
//                
//                
//            }
//        }
//    }];


}

#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LeftCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyLeftCell"];
    LeftModel *model = self.dataArry[indexPath.row];
    cell.model = model;
    return cell;
}

-(NSArray *)dataArry{
    if (!_dataArry) {
        _dataArry = [LeftModel lefts];
    }
    return _dataArry;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   // LeftModel *model = self.dataArry[indexPath.row];
    if (indexPath.row == 0) {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *Vc = [sb instantiateViewControllerWithIdentifier:@"LYMinute"];
        [self presentViewController:Vc animated:YES completion:nil];
    }
}
//    //跳到我的主页
//    if (indexPath.row == 0) {
//        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        MymyController *vc = [sb instantiateViewControllerWithIdentifier:@"MymyController"];
//        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
//        nav.title = model.name;
//        vc.image = _myImageV.image;
//        [self presentViewController:nav animated:YES completion:nil];
//    }else if (indexPath.row == 1){
//        CollectionController *vc = [[CollectionController alloc] init];
//        [self presentViewController:vc animated:YES completion:nil];
//    }else if(indexPath.row == 2){
//        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        UINavigationController *nav = [sb instantiateViewControllerWithIdentifier:@"AboutUsController"];
//        [self presentViewController:nav animated:YES completion:nil];
//    }else if (indexPath.row == 3){
//        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        UINavigationController *nav = [sb instantiateViewControllerWithIdentifier:@"UserFeedbackController"];
//        [self presentViewController:nav animated:YES completion:nil];
//    }else if (indexPath.row == 4){
//        [self alters:@"您选择退出登录" message:@"是否退出登录？"];
//    }
//}

//- (void)imageNotifition:(NSNotification *)noti {
//    _myImageV.image = noti.object;
//}

//- (void)viewWillAppear:(BOOL)animated{
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageNotifition:) name:@"UserAvatarNotification" object:nil];
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    _myNameL.text = [user stringForKey:@"myName"];
//    NSString *str = [user stringForKey:@"signature"];
//    if (!str) {
//        _signatureL.text = @"";
//    }else {
//        _signatureL.text = str;
//    }
//    
//}

//- (void)alters:(NSString *)title message:(NSString *)message {
//    UIAlertController *alter = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
//    
//    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        ViewController *vc = [sb instantiateViewControllerWithIdentifier:@"ViewController"];
//        [UIApplication sharedApplication].keyWindow.rootViewController = vc;
//    }];
//    [alter addAction:action];
//    
//    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//    }];
//    [alter addAction:action2];
//    
//    [self presentViewController:alter animated:YES completion:^{
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            [alter dismissViewControllerAnimated:YES completion:nil];
//        });
//    }];
//}


//#pragma mark - getter
//- (NSArray *)dataArray{
//    if (!_dataArray) {
//        _dataArray = [LeftModel lefts];
//    }
//    return _dataArray;
//}


@end
